package com.gome.oa.handler;

import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;

import com.gome.oa.custom.GMBrowser;
import com.gome.oa.dialog.PopupBrowserDialog;
import com.teamdev.jexplorer.DialogHandler;

/**
 *
 * @author: tang li
 * @date: 2016年8月22日
 * @desc: 
 *
 */
public class BrowserDialogHandler implements DialogHandler {
	
	private GMBrowser browser;
	
	private PopupBrowserDialog popupDialog;
	
	public BrowserDialogHandler(GMBrowser browser, PopupBrowserDialog popupDialog) {
		this.browser = browser;
		this.popupDialog = popupDialog;
	}

	@Override
	public int showDialog(final String title, final String text, final int type) {
		//弹出了javasciprt框 alert/confirm...
		browser.setAllowExecJs(false);
		//确认或取消
		if (type == 33) {
			int ret = JOptionPane.showConfirmDialog(popupDialog, text, title, JOptionPane.YES_NO_OPTION);
			if (ret == 0) {
				return 1;
			} else {
				return 0;
			}
		}
		else {
			SwingUtilities.invokeLater(new Runnable() {
				@Override
				public void run() {
					JOptionPane.showConfirmDialog(popupDialog, text, title, JOptionPane.DEFAULT_OPTION);
				}
			});
			return DialogHandler.IDOK;
		}
	}

}
